package com.suddev.bigdata.utils

import org.apache.spark.serializer.KryoSerializer
import org.apache.spark.sql.SparkSession
import org.apache.spark.{SparkConf, SparkContext}
import org.datasyslab.geospark.serde.GeoSparkKryoRegistrator

/**
  * @author Rand
  * @date 2019/9/27 0027
  */
object ContextUtils {

  def getSparkContext(appName:String,master:String="local[*]"): SparkContext ={
    val conf = new SparkConf().
      setAppName(appName).setMaster(master).
      set("spark.serializer",classOf[KryoSerializer].getName).
      set("spark.kryo.registrator", classOf[GeoSparkKryoRegistrator].getName)
    new SparkContext(conf)
  }

  def getSparkSession(appName:String,master:String="local[*]"):SparkSession ={
    SparkSession.builder().
      config("spark.serializer",classOf[KryoSerializer].getName).
      config("spark.kryo.registrator", classOf[GeoSparkKryoRegistrator].getName).
      master(master).appName(appName).getOrCreate()
  }

}
